
public class Bomb extends PlaygroundElement implements Runnable{
	Thread t;
	public Bomb(int x, int y, Game parent) throws InterruptedException {
		this.x=x;
		this.y=y;
		this.parent=parent;
		parent.pg.addObject(x, y, this);
		t = new Thread(this, "waitingBomb");
		t.start();
	}
	
	public int getType() {
		return 4;
	}
	
	private void explode() {
		boolean hit = false;
		int i=0;
		
		while ((!hit)&&(i<3)) {
			if (parent.pg.removeObject(x+i, y)) {
				hit = true;
			}
			i++;
		}
		
		hit = false;
		i=0;
		
		while ((!hit)&&(i<3)) {
			if (parent.pg.removeObject(x+i, y)) {
				hit = true;
			}
			i++;
		}
		
		hit = false;
		i=0;
		while ((!hit)&&(i<3)) {
			if (parent.pg.removeObject(x, y+i)) {
				hit = true;
			}
			i++;
		}
		
		hit = false;
		i=0;
		
		while ((!hit)&&(i<3)) {
			if (parent.pg.removeObject(x, y-i)) {
				hit = true;
			}
			i++;
		}
		
		hit = false;
		i=0;
		while ((!hit)&&(i<3)) {
			if (parent.pg.removeObject(x-i, y)) {
				hit = true;
			}
			i++;
		}
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			for(int i = 5; i > 0; i--) {
	            System.out.println("Bomb: " + i);
	            // Let the thread sleep for a while.
	            Thread.sleep(500);
	         }
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		explode();
	}
}
